package com.tsd.system.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.dao.SysLogInfoMapper;
import com.tsd.system.entity.SysLogInfo;
import com.tsd.system.entity.SysLogInfoExt;
import com.tsd.system.service.SysLogInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysLogInfo 服务实现层
 *
 * @author Hillpool
 * @date 2019/07/31 14:22:11
 */
@Service
public class SysLogInfoServiceImpl extends BaseServiceImpl implements SysLogInfoService {

    @Resource
    private SysLogInfoMapper sysLogInfoMapper;

    @Override
    public SysLogInfo queryByPrimaryKey(Long id) throws Exception {
        return sysLogInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteByPrimaryKey(Long id) throws Exception {
        sysLogInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveSysLogInfo(SysLogInfoExt record) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            record.setCreate_time(new Date());
            record.setYear_month(HlpUtils.date2String(record.getCreate_time(), "yyyyMM"));
            sysLogInfoMapper.insertSelective(record);
        } else {
            sysLogInfoMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<SysLogInfo> findSysLogInfos(Map<String, Object> params, PageBean page) throws Exception {
        return sysLogInfoMapper.selectByPage(params, page);
    }

    @Override
    public List<SysLogInfo> findSysLogInfos(Map<String, Object> params) throws Exception {
        return sysLogInfoMapper.selectByParams(params);
    }
}
